// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import axios from 'axios'
import {baseUrl} from '@/config/index'

import '../static/css/animate.css'
import 'element-ui/lib/theme-chalk/index.css'
import './common/iconfont.css'

// 配置axios
axios.defaults.baseURL = baseUrl
axios.defaults.withCredentials = true
axios.interceptors.request.use(config => {
  const excludeUrls = ['/api/v1/user/register', '/api/v1/user/register']
  const token = localStorage.getItem('token')
  // 判断请求是否需要添加token
  if (!excludeUrls.includes(config.url) && token) {
    config.headers.common['Authorization'] = token
  }
  return config
}, error => {
  return Promise.reject(error)
})
Vue.prototype.axios = axios

Vue.config.productionTip = false

Vue.use(ElementUI)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
